<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of search
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Search extends CI_Controller {

    //put your code here


    function search() {
        parent :: __construct();
        $this->load->model('pickup_model');
        $this->load->model('listing_model');
        
        
    }
    
    function used($para) {
        if ($para == 'car') {
            $data['car_make'] = $this->pickup_model->get_car_makes();
            $data['car_country'] = $this->pickup_model->populate_country();
            $data['min_year'] = $this->pickup_model->populate_year('P', 15, date('Y', now()));
            $data['max_year'] = $this->pickup_model->populate_year('P', 15, date('Y', now()));
            $this->load->view('car_search_used',$data);
        }  
        elseif ($para == 'motorcycle') {
            //--Code here
        }
    }

//-- Search Car (USED/NEW) as per Search Criteria --Subha(29/07/2012)--//    
   function search_car($para){
       if ($para == 'used') {
           $this->form_validation->set_rules('car_make','car_make','trim|required');
           if($this->form_validation->run())
           {
           $car = array(
           'car_make'        => $_POST['car_make'],
           'car_model'       => $_POST['car_model'],
           'car_country'     => $_POST['car_country'],
           'car_state'       => $_POST['car_state'],
           'car_city'        => $_POST['car_city'],
           'car_min_year'    => $_POST['car_min_year'],
           'car_max_year'    => $_POST['car_max_year'],
           'car_budget'      => $_POST['car_budget']    
           );
           $data['used_car'] = $this->listing_model->search($car,'car');
           $data['car_make'] = $this->pickup_model->get_car_makes();
           $data['car_country'] = $this->pickup_model->populate_country();
           $data['min_year'] = $this->pickup_model->populate_year('P', 15, date('Y', now()));
           $data['max_year'] = $this->pickup_model->populate_year('P', 15, date('Y', now()));
           $this->load->view('car_search_used',$data);
           }
           else
           {
               $this->session->set_flashdata('message','Please Choose Car Make');
               redirect('search/used/car');
           }
          
           
           
       }
       
   } 
    

   
   
   
}
?>
